<?php
namespace app\screenshot\home;
use app\common\controller\Common;
use think\Db;
use think\Loader;
Loader::import('token.token',EXTEND_PATH,'.php');


class Token extends Common
{
    public function index(){
      ob_clean();
    $wechatObj = new \wechatAPI();

//注意：第一步验证时打开，验证完成之后就可以注释了
   //$wechatObj->isValid();


    $postStr = file_get_contents("php://input");
        
    $accept_info = json_decode($postStr,true);

    if($accept_info){
        $ToUserName = $accept_info['ToUserName'];
        $FromUserName = $accept_info['FromUserName'];
        $CreateTime = $accept_info['CreateTime'];
        $MsgType = $accept_info['MsgType'];
        //$MsgId = $accept_info['MsgId'];
        // $Encrypt = $accept_info['Encrypt'];
        
        $data = array();
        
            
            $Content = $accept_info['Content'];//文本内容
        
            // "touser": "OPENID",
            // "msgtype": "link",
            // "link": {
            //       "title": "Happy Day",
            //       "description": "Is Really A Happy Day",
            //       "url": "URL",
            //       "thumb_url": "THUMB_URL"
            // }
              
            $data['touser'] = $FromUserName;
            $data['msgtype'] = 'link';
            $data['link']['title'] = urlencode(config('module_screenshot.kf_title'));//urlencode 解决中文乱码问题
            $data['link']['description'] = urlencode(config('module_screenshot.kf_body'));//urlencode 解决中文乱码问题
            $data['link']['url'] = config('module_screenshot.kf_url');  
            $data['link']['thumb_url'] = 'http://'.$_SERVER['HTTP_HOST'].config('module_screenshot.kf_img');  
            $wechatObj->send($data);
                 
        
            //else if 可以做好多事
      
        
        echo '<xml><ToUserName><![CDATA['.$FromUserName.']]></ToUserName><FromUserName><![CDATA['.$ToUserName.']]></FromUserName><CreateTime>'.$CreateTime.'</CreateTime><MsgType><![CDATA[transfer_customer_service]]></MsgType></xml>';
       }
    }
}
?>